﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using IndicoInterface;
using IndicoInterface.SimpleAgendaDataModel;
using DeepTalkWF;
using System.IO;

namespace DeepTalkWFTest
{
    /// <summary>
    /// Summary description for t_DownloadTalks
    /// </summary>
    [TestClass]
    public class t_DownloadTalks
    {
        public t_DownloadTalks()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void TestSimpleDownload()
        {
            AgendaInfo info = new AgendaInfo("http://agenda.hep.wisc.edu/conferenceOtherViews.py?view=standard&confId=60");
            Meeting m = info.GetNormalizedConferenceData();

            DirectoryInfo temp = new DirectoryInfo(Path.GetTempPath() + "\\DTTests");

            var results = Utilities.RunWFByType(typeof(DownloadTalks),
                new Dictionary<string, object> { {"MeetingInfo", m},
                {"TempDirectory", temp}});

            Assert.IsNotNull(results, "Came back null!");
            Assert.IsTrue(results.ContainsKey("DownloadedMeetingInfo"), "Missing outgoing meeting info!");

            /// Make sure at least one talk came down ok... More extensive underlying tests
            /// will have already tested that all talks come down ok!
            /// 

            Meeting result = results["DownloadedMeetingInfo"] as Meeting;
            Assert.IsTrue(result != null, "No meeting came back!");
            Assert.IsTrue(result.Sessions != null, "No sessions in the meeting!?");
            Assert.IsTrue(result.Sessions.Length > 0, "No sessions!?");
            Assert.IsTrue(result.Sessions[0].Talks.Length > 1, "No talks in first session!");
            Assert.IsTrue(result.Sessions[0].Talks[1].SlideURL != null, "Slide url is null for first talk!");
            Assert.IsTrue(File.Exists(result.Sessions[0].Talks[1].SlideURL), "Missing downloaded url!?");
        }
    }
}
